package com.android.jumishangcheng.pojo;

import android.util.Log;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;


public class ParentPojo implements Serializable {
    private static final long serialVersionUID = 1L;
    public boolean flag;
    public int time;
    public String code; //响应码
    public String msg; //响应提示


    private String errflag;//suc or err
    private String errtype;//interface name
    private String errmessage;//err or suc message

    public String getErrflag() {
        return errflag;
    }

    public void setErrflag(String errflag) {
        this.errflag = errflag;
    }

    public String getErrtype() {
        return errtype;
    }

    public void setErrtype(String errtype) {
        this.errtype = errtype;
    }

    public String getErrmessage() {
        return errmessage;
    }

    public void setErrmessage(String errmessage) {
        this.errmessage = errmessage;
    }
//	@Override
//	public String toString() {
//		return "ParentPojo [errflag=" + errflag + ", errtype=" + errtype
//				+ ", errmessage=" + errmessage + "]";
//	}

    /**
     * 反射出所有字段值
     */
    @Override
    public String toString() {
        ArrayList<Field> list = new ArrayList<Field>();
        Class<?> clazz = getClass();
        list.addAll(Arrays.asList(clazz.getDeclaredFields()));//得到自身的所有字段
        StringBuilder sb = new StringBuilder();
        while (clazz != Object.class) {
            clazz = clazz.getSuperclass();//得到继承自父类的字段
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                int modifier = field.getModifiers();
                if (Modifier.isPublic(modifier) || Modifier.isProtected(modifier)) {
                    list.add(field);
                }
            }
        }
        Field[] fields = list.toArray(new Field[list.size()]);
        for (Field field : fields) {
            String fieldName = field.getName();
            try {
                Object obj = field.get(this);
                sb.append(fieldName);
                sb.append("=");
                sb.append(obj);
                sb.append("\n");
            } catch (IllegalAccessException e) {
                Log.e("",e.toString());
            }
        }
        return sb.toString();
    }
}
